#include<iostream>
using namespace std;
int main() {
	int min, max, a, i = 0, j = 0, s, d, e;
	int n[10];
	cin >> a;
	for (int c = 0; c < a; c++) {
		cin >> n[c];
	}
	min = n[0]; max = n[a - 1];
	for (int b = 1; b < a; b++) {
		if (min > n[b]) {
			min = n[b];
			i = b;
		}
	}
	d = n[0];
	n[0] = n[i];
	n[i] = d;
	for (int c = 1; c < a; c++) {
		if (max < n[c]) {
			max = n[c];
			j = c;
		}
	}
	e = n[a - 1];
	n[a - 1] = n[j];
	n[j] = e;
	for (int c = 0; c < a; c++) {
		cout << n[c] << " ";
	}
	return 0;
}
